Skip to content

4.x: Fix Streamable.intervalRange emitting nothing when start + count overflows - #8398

Merged
akarnokd merged 1 commit into
ReactiveX:4.xfrom
Dev-next-gen:fix-intervalrange-max-end
Nov 19, 2026
Merged

akarnokd merged 1 commit into
ReactiveX:4.xfrom
Dev-next-gen:fix-intervalrange-max-end

Conversation

@Dev-next-gen

Copy link
Copy Markdown
Contributor

Streamable.intervalRange(1, Long.MAX_VALUE, ...) completes without emitting anything. The Javadoc suggests Long.MAX_VALUE as the count for an unlimited range, and the factory overflow check accepts this call (underNoOverflowLong covers the boundary), but the sequence is empty. The same happens for any range whose last value is exactly Long.MAX_VALUE, for example intervalRange(Long.MAX_VALUE - 2, 3, ...).

StreamableIntervalRange.stream() creates the streamer with end = start + itemCount, which wraps to Long.MIN_VALUE in these cases. next() then sees counterLocal >= end on the first call and returns false, and run() disposes the timer on its first tick because c + 1 >= end.

The fix compares through a subtraction (counterLocal - end >= 0 and c + 1 - end >= 0), which stays correct when end wrapped since the distance from start to end never exceeds Long.MAX_VALUE. count == 0 still ends right away. This is the same boundary #8337 fixed for range/rangeLong; FlowableIntervalRange already handles it with c == end.

I added maxValueEnd and unlimitedFromOne to StreamableIntervalRangeTest. Before the fix both fail with got: 0 [] and one completion. After the fix the whole StreamableIntervalRangeTest passes (23 tests, 1 skipped as before).

AI disclosure: the defect, the fix and the tests were found and written with AI. Found by a defect-hunting pipeline I build and run (Dev-next-gen), using Claude Code with Anthropic's Claude Opus 5.5.

… overflows

intervalRange accepts start + count == Long.MAX_VALUE + 1, for example
start = 1 with count = Long.MAX_VALUE, which the Javadoc suggests for an
unlimited range. The streamer stored end = start + count, which wraps to
Long.MIN_VALUE, so counterLocal >= end held right away and the sequence
completed empty. Compare against the end through a subtraction so the
wrapped end still works, as Flowable.intervalRange does with c == end.
@github-actions

Copy link
Copy Markdown

🐷 TruffleHog + Entropy Beauty Scan

Average entropy of changed code: 4.576 bits/char
Verdict: ✅ Mid-4 beauty detected (thoughtful human code!)

Changed files entropy:

src/main/java/io/reactivex/rxjava4/internal/operators/streamable/StreamableIntervalRange.java: 4.367
src/test/java/io/reactivex/rxjava4/internal/operators/streamable/StreamableIntervalRangeTest.java: 4.784

✅ No secrets or suspicious high-entropy strings found.

Mid-4 beauty heuristic in action — powered by our entropy chats! 😊

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.61%. Comparing base (ca68c46) to head (6b5fa0c).
⚠️ Report is 1 commits behind head on 4.x.

Additional details and impacted files
@@             Coverage Diff              @@
##                4.x    #8398      +/-   ##
============================================
+ Coverage     98.60%   98.61%   +0.01%     
  Complexity     7182     7182              
============================================
  Files           826      826              
  Lines         51038    51038              
  Branches       6944     6944              
============================================
+ Hits          50326    50333       +7     
+ Misses          481      477       -4     
+ Partials        231      228       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@akarnokd akarnokd added this to the 4.0 milestone Nov 19, 2026
@akarnokd
akarnokd merged commit e9c5d48 into ReactiveX:4.x Nov 19, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants